// pages/dgame2/dgame2.js

var second = 35
var poid ,acidacid,randId,sitetype
var url='https://www.juquduo.com/juquduo/question/rand'

Page({

  /**
   * 页面的初始数据
   */
  data: {
    second:'',
    setInter:'',
    quesmsg:[],
    Answer:'',pid:'',
    txtA:'',  txtB:'',  txtC:'',  txtD:'',
    optionsbgA:'https://www.juquduo.com/static/resourse/question/选项.png',
    optionsbgB:'https://www.juquduo.com/static/resourse/question/选项.png',
    optionsbgC:'https://www.juquduo.com/static/resourse/question/选项.png',
    optionsbgD:'https://www.juquduo.com/static/resourse/question/选项.png',
    Question:'',
    AnswerA:'',
    AnswerB:'',
    arr:[1,2,3],
    AnswerTrue:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // pid是序号，通过的关卡数
    poid = options.pid
    acidacid = options.acid
    sitetype = options.sitetype
    console.log('问题页面，点位序号',poid)
    var that=this;
    var openid = wx.getStorageSync('openid')
    //获取随机题
    wx.request({
      url: url,
      data:{
        openid:openid,
        activityId:acidacid,
        source:'activity_users'
      },
      method: 'GET',
      success:function(res){
        that.setData({
          Question:res.data[0].Question,
          AnswerA:res.data[0].AnswerA,
          AnswerB:res.data[0].AnswerB,
          AnswerC:res.data[0].AnswerC,
          AnswerD:res.data[0].AnswerD,
          AnswerTrue:res.data[0].AnswerTrue
        })
        randId = res.data[0].Id
        console.log('问题页面的返回值',randId)

      }
    })
    wx.setNavigationBarTitle({
      title: '正在游戏',
    })

    // var quesmsg = wx.getStorageSync('pointmsg')
    // console.log('问题页面接收的信息',quesmsg)
    // this.setData({quesmsg:quesmsg})
    // var qanda = JSON.parse(quesmsg.Radios)
    // console.log(quesmsg)
    // this.setData({AA:qanda.A[0],BB:qanda.B[0],CC:qanda.C[0],DD:qanda.D[0],Answer:quesmsg.Answer})
  },
  //选择选项
  achoice(){
    if(this.data.AnswerTrue=='1'){
      setTimeout(function(){
        wx.redirectTo({
          url: '../dgameques/dgameques?state=1&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
        } ,300)
      this.setData({txtA:'white',optionsbgA:'https://www.juquduo.com/static/resourse/game3/bggreen.png',panduanA:'https://www.juquduo.com/static/resourse/game3/dui.png'})
      console.log('回答正确')
    }else{  console.log('回答错误')
    setTimeout(function(){
      wx.redirectTo({
        url: '../dgameques/dgameques?state=0&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
    } ,300)
      this.setData({txtA:'white',optionsbgA:'https://www.juquduo.com/static/resourse/game3/bgred.png',panduanA:'https://www.juquduo.com/static/resourse/game3/cha.png'})
    }
    // clearInterval(this.data.setInter)
    // second = 15
  },
  bchoice(){
    if(this.data.AnswerTrue=='2'){
      setTimeout(function(){
      wx.redirectTo({
        url: '../dgameques/dgameques?state=1&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
    } ,300)
      this.setData({txtB:'white',optionsbgB:'https://www.juquduo.com/static/resourse/game3/bggreen.png',panduanB:'https://www.juquduo.com/static/resourse/game3/dui.png'})
      console.log('回答正确')
    }else{  console.log('回答错误')
    setTimeout(function(){
      wx.redirectTo({
        url: '../dgameques/dgameques?state=0&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
    } ,300)
      this.setData({txtB:'white',optionsbgB:'https://www.juquduo.com/static/resourse/game3/bgred.png',panduanB:'https://www.juquduo.com/static/resourse/game3/cha.png'})
    }
    // clearInterval(this.data.setInter)
    second = 15
    // var t1 = setTimeout(function(){console.log('计时器1秒')},300); 
    // clearTimeout(t1); 
  },
  cchoice(){
    if(this.data.AnswerTrue=='3'){
      setTimeout(function(){
      wx.redirectTo({
        url: '../dgameques/dgameques?state=1&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
    } ,300)
      this.setData({txtC:'white',optionsbgC:'https://www.juquduo.com/static/resourse/game3/bggreen.png',panduanC:'https://www.juquduo.com/static/resourse/game3/dui.png'})
      console.log('回答正确')
    }else{  console.log('回答错误')
    setTimeout(function(){
      wx.redirectTo({
        url: '../dgameques/dgameques?state=0&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
    } ,300)
      this.setData({txtC:'white',optionsbgC:'https://www.juquduo.com/static/resourse/game3/bgred.png',panduanC:'https://www.juquduo.com/static/resourse/game3/cha.png'})
    }
    // clearInterval(this.data.setInter)
    // second = 15
  },
  dchoice(){
    if(this.data.AnswerTrue=='4'){
      setTimeout(function(){
      wx.redirectTo({
        url: '../dgameques/dgameques?state=1&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
    } ,300)
      this.setData({txtD:'white',optionsbgD:'https://www.juquduo.com/static/resourse/game3/bggreen.png',panduanD:'https://www.juquduo.com/static/resourse/game3/dui.png'})
      console.log('回答正确')
    }else{  console.log('回答错误')
    setTimeout(function(){
      wx.redirectTo({
        url: '../dgameques/dgameques?state=0&pid='+poid+'&randid='+randId+'&sitetype='+sitetype, })
    } ,300)
      this.setData({txtD:'white',optionsbgD:'https://www.juquduo.com/static/resourse/game3/bgred.png',panduanD:'https://www.juquduo.com/static/resourse/game3/cha.png'})
    }
    // clearInterval(this.data.setInter)
    // second = 15
  },
  onShow(){
    wx.hideHomeButton({
      success: (res) => {},
    })
  },
  onReady: function () {

  },
})